<template>
  <div class="swiper-container" ref="ContainerList">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="item in imgList" :key="item.id">
         <img :src="item.imgUrl" />
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>

    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
  </div>
</template>

<script>
import Swiper from "swiper";
export default {
  name: "Carsousel",
  //父子传参
  props: ["imgList"],
  watch: {
    //数据监听
    imgList: {
       immediate: true,
      handler() {
        this.$nextTick(() => {
            // console.log("imgList===>"+imgList);
          var mySwiper = new Swiper(this.$refs.ContainerList, {
            loop: true, // 循环模式选项
            
            // 如果需要分页器
            pagination: {
              el: ".swiper-pagination",
              //点击小球的时候也切换图片
              clickable: true,
            },

            // 如果需要前进后退按钮
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
            autoplay: { disableOnInteraction: false }
          });
        });
      },
    },
  },
};
</script>

<style lang="less" scope></style>
